/**
 * Copyright 2015 Qiyi Inc. All rights reserved.
 *
 * @file:   Stream.Dao.js
 * @path:   js-src/Stream/
 * @desc:   负责本模块的远程调用的静态对象
 * @author: jiegang@qiyi.com
 * @date:   2015-01-07
 */
qui(
    function (require, exports, module) {

        Stream.Dao = $.extend({}, Ancestor.Dao, {

            // 直播流添加
            addStreamData: function (data, callback) {
                var options = {
                    url: '/api/stream/create',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, '/stream/create');
            },

            // 直播流修改
            modifyStreamData: function (data, callback) {
                var options = {
                    url: '/api/stream/edit',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, '/stream/edit');
            },


            // 直播流删除
            delStreamData: function (data, callback) {
                var options = {
                    url: '/api/stream/deleteById',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, '/stream/deleteById');
            },

            // 获取直播流数据列表
            getStreamData: function (data, callback) {
                var options = {
                    url: '/api/stream/list',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, '/stream/list');

            },

            // 获取创建直播流数信息
            getStreamInfo: function (data, callback) {
                var options = {
                    url: '/api/liveStream/getList',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, '/liveStream/getList');
            },


            // 流名称关联频道
            bindStreamName: function (data, callback) {
                var options = {
                    url: '/api/stream/binding',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, '/stream/binding');
            },

            // 流信息操作
            streamInfoOperate: function (data, callback) {
                var options = {
                    url: '/api/' + data.api,
                    dataType: 'json',
                    data: data.data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, '/' + data.api);
            },

            getStreamNameCodeData: function (url, data, callback) {

                var options = {
                    url: url,
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, url.split('api')[1]);
            },

            // 调用第三方接口创建轮播台流
            encoderOperation: function (data, callback) {
                $.ajax({
                    url: '/api/redirect',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    beforeSend: function (request) {
                        var auth = Ancestor.Util.getAuth('/redirect');
                        request.setRequestHeader('Sign', auth.sign);
                        request.setRequestHeader("Time", auth.clientTime);
                        request.setRequestHeader("From", auth.from);
                    },
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                });
            },

            getCurrentProgram: function (data, callback) {
                var options = {
                    url: '/api/program/list',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, '/program/list');
            },

            // 保存全景直播参数
            addVideoTypeData: function (data, callback) {
                var options = {
                    url: '/api/channel/setPanoFormat',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, '/channel/setPanoFormat');
            },

            // 保存3D直播参数
            saveThreeD: function (data, callback) {
                var options = {
                    url: '/api/channel/setThreeD',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                };

                Ancestor.Dao.ajax(options, '/channel/setThreeD');
            },


            getCutterIdInfo: function (data, callback) {
                var options = {
                    url: '/api/stream/cutterIdInfo',
                    dataType: 'json',
                    data: data,
                    method: 'get',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data)
                    }
                };

                Ancestor.Dao.ajax(options, '/stream/cutterIdInfo');
            },

            getCutterIdInfoNew: function (data, callback) {
                $.ajax({
                    url: '/api/redirect',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    beforeSend: function (request) {
                        var auth = Ancestor.Util.getAuth('/redirect');
                        request.setRequestHeader('Sign', auth.sign);
                        request.setRequestHeader("Time", auth.clientTime);
                        request.setRequestHeader("From", auth.from);
                    },
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                });
            },

            switchBackup: function (data, callback) {
                var options = {
                    url: '/api/stream/switchBackup',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data)
                    }
                };

                Ancestor.Dao.ajax(options, '/stream/switchBackup');
            },
            //获取频道数据
            getChannelData:function(data,callback){
                var self =this;
                var options = {
                    url: '/api/channel/list',
                    dataType: 'json',
                    data: data,
                    method: 'post',
                    success: function (data) {
                        callback.call(this, data);
                    },
                    error: function (data) {
                        callback.call(this, data);
                    }
                }
                Ancestor.Dao.ajax(options, '/channel/list');
            }

        });
    }
);